<template>
  <div class="">
    <el-row>
      <el-col :span="24">
        <div class="page-filter mb10 fl">
          <el-form ref="filter" :model="filter" label-width="0">
            <el-form-item class="mr10 mb5 fl">
              <SupplierSelect v-model="filter.sup_id" />
            </el-form-item>
            <el-form-item class="mr10 mb5 fl" style="width: 300px">
              <el-button size="small" @click="app.resetFields($refs['filter'].$parent,'filter')">清 空</el-button>
              <el-button type="primary" size="small" @click="getList">查 询</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-col>
      <el-col :span="24">
        <el-table
          v-loading="app.loading"
          class="search-table"
          :data="list"
          border
          :summary-method="getSummaries"
          show-summary
          fit
          highlight-current-row
          style="width: 100%;"
        >
          <el-table-column label="序号" align="center" width="56px">
            <template slot-scope="{$index}">
              {{ $index + 1 }}
            </template>
          </el-table-column>
          <el-table-column label="供应商名称" min-width="220px">
            <template slot-scope="{row}">
              {{ row.sup_name ? row.sup_name : '仓库' }}
            </template>
          </el-table-column>
          <el-table-column label="采购金额" align="right" width="140px">
            <template slot-scope="{row}">
              {{ app.toFix(row.price + row.additional - row.reduction, 2) }}
            </template>
          </el-table-column>
          <el-table-column label="已付款金额" align="right" width="140px">
            <template slot-scope="{row}">
              {{ app.toFix(row.pay, 2) }}
            </template>
          </el-table-column>
          <el-table-column label="未付款金额" align="right" width="140px">
            <template slot-scope="{row}">
              {{ app.toFix(row.price + row.additional - row.reduction - row.pay, 2) }}
            </template>
          </el-table-column>
          <el-table-column label="已开票金额" align="right" width="140px">
            <template slot-scope="{row}">
              {{ app.toFix(row.has_tax, 2) }}
            </template>
          </el-table-column>
          <el-table-column label="未开票金额" align="right" width="140px">
            <template slot-scope="{row}">
              {{ app.toFix(row.price + row.additional - row.reduction - row.has_tax, 2) }}
            </template>
          </el-table-column>
          <!-- <el-table-column label="追加金额" align="right" width="140px">
            <template slot-scope="{row}">
              {{ app.toFix(row.additional, 2) }}
            </template>
          </el-table-column>
          <el-table-column label="追减金额" align="right" width="140px">
            <template slot-scope="{row}">
              {{ app.toFix(row.reduction, 2) }}
            </template>
          </el-table-column>
          <el-table-column label="合计金额" align="right" width="140px">
            <template slot-scope="{row}">
              {{ app.toFix(row.price-row.additional+row.reduction, 2) }}
            </template>
          </el-table-column> -->
          <el-table-column label="项目明细" align="center" width="140px">
            <template slot-scope="{row}">
              <a style="color: blue" 
                href="javascript:void(0)"
                @click="handleDialog({...{sup_id: row.sup_id}, ...
                {dRef: 'dialog', dTitle: '项目明细', dType: 'edit', dField: dField}})"
              >详情</a>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="filter.pageAll>0" :total="filter.pageAll" :page.sync="filter.pageCurrent" :limit.sync="filter.pageNumber" @pagination="getList" />
      </el-col>
    </el-row>
    <Dialog ref="dialog" :info="dialog" />
  </div>
</template>

<script>
import { payables } from '@/api/statistics/statistics'
import page from '@/utils/page'
import SupplierSelect from '@/myComponents/SupplierSelect'
import Dialog from './components/payables-pro-dialog'

export default {
  name: '',
  components: { SupplierSelect, Dialog },
  extends: page,
  props: {
    reqList: {
      default: payables,
      type: Function
    }
  },
  data() {
    return {
      price: {},
      dField: ['sup_id']
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getListAfter(e) {
      this.price = e.info || {}
    },
    getSummaries() {
      const sums = []
      sums[0] = '合计'
      sums[1] = ''
      sums[2] = this.app.toFix(this.price.price + this.price.additional - this.price.reduction, 2)
      sums[3] = this.app.toFix(this.price.pay, 2)
      sums[4] = this.app.toFix(this.price.price + this.price.additional - this.price.reduction - (this.price.pay ? this.price.pay : 0), 2)
      sums[5] = this.app.toFix(this.price.has_tax, 2)
      sums[6] = this.app.toFix(this.price.price + this.price.additional - this.price.reduction - (this.price.has_tax ? this.price.has_tax : 0), 2)
      return sums
    }
  }
}
</script>
<style scoped>
</style>
